import { defineStore } from 'pinia'
import { reactive, ref, computed } from 'vue'
import request from '@/utils/request.js'
import axios from 'axios'
// import {
//   editWarehouse,
//   addWarehouse,
//   delWarehouse
// } from '@/service/warehouse/index.js'
import responseMessage from '@/utils/response.js'

interface TableData {
  create_time: string
  update_time: string
  name: string
  id: string
  city: number | string[]
  proj: string
  category: string
  remark: string
}
type Page = {
  pagenum: number
  size: number
  total: number
}
const useTaskStore = defineStore('task', () => {
  const taskDetailList = ref<any>([])
  const page = reactive<any>({
    pagenum: 1,
    size: 50,
    total: 0
  })
  const generateTask = {
    sourceFilePath: '',
    fileName: '',
    taskType: ''
  }
  /* 仓库管理 */
  //获取仓库列表
  async function getTaskDetailList(params: object) {
    const res = await request.get('/querySubTasks', {
      params
    })
    taskDetailList.value = res.data
    return res.data
  }
  //生成任务
  async function generateTaskAPI() {
    const data = generateTask
    // console.log(generateTask, '111')
    const res = await request.post('/generateMainTask', data)
    responseMessage(res)
    return res
  }
  //编辑仓库信息
  async function editWarehouse(addForm: TableData) {
    const res = await request.put('/admin/warehouse/', addForm)
    responseMessage(res)
  }
  //删除仓库信息
  async function delWarehouseHandler(id: number) {
    const res = await request.delete('/admin/material/', {
      params: {
        id: id
      }
    })
    responseMessage(res)
  }
  //导出仓库中的物资图片zip文件


  return { getTaskDetailList, page, taskDetailList, generateTask, generateTaskAPI }
})

export default useTaskStore
